#pragma once
#include "base_define.h"
#include "base_type.h"

#define BUFFER_SIZE	(1 * 1024)
#define BUFFER_GROW	(16 * 1024)

class buffer_t  
{
public:
	buffer_t( uint32 grow = BUFFER_GROW );
	buffer_t( uint32 size, uint32 grow = BUFFER_GROW );
	buffer_t( const void* buf, uint32 len );
	virtual ~buffer_t();
	
	uchar *		buffer() { return (uchar*)m_buffer; }
	uint32		length() { return m_length; }
	uint32      size(){ return m_size; }
	
	void        reserve( uint32 bytes );
	void		descard( uint32 bytes );
	
	void		reset( uint32 size = BUFFER_SIZE, uint32 grow = BUFFER_GROW );
	
	void		write( const void* buf, uint32 len );
	
protected:

	uchar *     m_buffer;
	uint32		m_length;
	uint32		m_size;
	uint32		m_grow;
	
	void		resize(uint32 size);
	void		clear();
};

typedef std::vector<buffer_t*> BUFFER_LIST;